package cn.com.vrv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.com.vrv.common.AbstractController;
import cn.com.vrv.entity.QueryObj;
import cn.com.vrv.entity.RecognitionModel;
import cn.com.vrv.service.RecognitionModelService;
import cn.com.vrv.service.RecognitionTaskService;
import cn.com.vrv.util.StringUtils;

/**
 * 模型控制器
 * 
 * @author 赵炎
 * @version [V1.00, 2017年11月21日]
 * @see [相关类/方法]
 * @since V1.00
 */
@Controller
@RequestMapping("model")
public class ModelController extends AbstractController
{
	 @Autowired
	 private RecognitionModelService recognitionModelService;
	  @Autowired
	   private RecognitionTaskService recognitionTaskService;
	  @Value("${upload.path}")
	   private String path;//配置文件上传路径
	  
	 @RequestMapping("list")
	 public String list(@RequestParam(value = "page", defaultValue = "0") Integer page,
	            @RequestParam(value = "size", defaultValue = "10") Integer size,Model model,QueryObj queryObj)
	 {
		 Page<RecognitionModel> pageModel=recognitionModelService.findBookCriteria(page, size, queryObj);
		 model.addAttribute("queryObj", queryObj);
		 model.addAttribute("page", pageModel);
		 model.addAttribute("ulr", "/model/list");
		 return "recognition/modelList";
	 }
	 
	 /**
	     * <一句话功能简述>
	     * <功能详细描述>
	     * 
	     * @return
	     * @see [类、类#方法、类#成员]
	     */
	    @RequestMapping("save")
	    public String add(RecognitionModel model)
	    {
	    	if(model.getModelId()!=null)
	    	{
	    		this.recognitionModelService.updateByModelId(model);
	    	}else
	    	{
	    		model.setCreateTime(StringUtils.getDate());
	    		 this.recognitionModelService.save(model);
	    	}
	        return "redirect:/model/list";
	    }
	    
	    @RequestMapping("form")
	    public String form(Model model,@Param("modelId") String modelId,@Param("view") String view)
	    {
	    	RecognitionModel models=new RecognitionModel();
	    	if(StringUtils.isNotEmpty(modelId))
	    	{
	    		models= this.recognitionModelService.findByModelId(modelId);
	        	if(StringUtils.isNotEmpty(view))
	        	{
	        		model.addAttribute("view", view);
	        	}
	    	}
	    	model.addAttribute("models", models);
	        return "recognition/modelForm";
	    }
	    
	    @RequestMapping("delete")
	    public String delete(RedirectAttributes redirectAttributes,@Param("modelId") String modelId)
	    {
	    	this.recognitionModelService.deleteByModelId(modelId);
	    	redirectAttributes.addAttribute("info","删除成功" );
	    	return "redirect:/model/list";
	    }
	    
}
